let pkg = {
  name: 'xmGallery',
}
export let USER_INFO_KEY = 'userInfo' + pkg.name
export let FORM_USER_INFO_KEY = 'FormuserInfo' + pkg.name
export const setItem = (key, value) => {
  localStorage.setItem(key, JSON.stringify(value))
}
export const setItem2 = (key, value) => {
  localStorage.setItem(key, value)
}
export const getItem = (key) => {
  return localStorage.getItem(key)
}
export const removeItem = (key) => {
  localStorage.removeItem(key)
}

export const getUserToken = () => {
  let user_info = getItem(USER_INFO_KEY)
  if (user_info) {
    return JSON.parse(user_info).token
  } else {
    return null
  }
}

export const saveUserInfo = (data) => {
  document.cookie = `usertokenxm=${data.token}`
  setItem(USER_INFO_KEY, data)
}
export const clearUserInfo = () => {
  document.cookie =
    'usertokenxm=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
  removeItem(USER_INFO_KEY)
}
export const getUserInfo = () => {
  return JSON.parse(getItem(USER_INFO_KEY))
}
export const saveLoginFormUserInfo = (data) => {
  setItem(FORM_USER_INFO_KEY, data)
}
export const getLoginFormUserInfo = () => {
  let data = getItem(FORM_USER_INFO_KEY)
  if (data) {
    return JSON.parse(data)
  }
  return null
}
export const clearLoginFormUserInfo = () => {
  removeItem(FORM_USER_INFO_KEY)
}
